package com.lagou.mr;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class SortReducer extends Reducer<IntWritable, NullWritable, IntWritable, IntWritable> {

    IntWritable keyIndex = new IntWritable();
    int index = 0;

    @Override
    protected void reduce(IntWritable key, Iterable<NullWritable> values, Context context)
            throws IOException, InterruptedException {
        //遍历value
        for (NullWritable v : values) {
            index++;
            keyIndex.set(index);
            //将索引作为key写入
            context.write(keyIndex, key);
        }
    }
}
